package com.learn.authentication.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/04/06
 * @description
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public class R<T> {
    private int code;
    private String msg;
    private T data;
    public static <T> R<T> OK(String msg, T data) {
        return R.<T>builder()
                .code(200)
                .msg(msg)
                .data(data)
                .build();
    }
    public static <T> R<T> OK(String msg) {
        return R.<T>builder()
                .code(200)
                .msg(msg)
                .build();
    }
    public static <T> R<T> OK(T data) {
        return R.<T>builder()
                .code(200)
                .msg("成功")
                .data(data)
                .build();
    }
    public static <T> R<T> FAIL(int code) {
        return FAIL(code, null);
    }
    public static <T> R<T> FAIL(int code, String msg) {
        return R.<T>builder()
                .code(code)
                .msg(msg)
                .build();
    }
}
